import 'package:flutter/material.dart';
import 'package:flutter_demo/utils/toast.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../utils/secure_storage.dart';

class FindPage extends StatefulWidget {
  const FindPage({super.key});

  @override
  State<FindPage> createState() => _FindPageState();
}

class _FindPageState extends State<FindPage> {
  String fileStringValue = "";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      body: Stack(
        children: [
          Center(
            child: Text("Find"),
          ),
          Padding(
            padding: EdgeInsets.only(top: 50),
            child: FilledButton(
              onPressed: () async {
                fileStringValue =
                    await SecureStorage.instance().readShare("name");

                Toast.showToast("ll$fileStringValue");

                setState(() {});
              },
              child: Text("读共享数据${fileStringValue}"),
            ),
          ),
          Column(
            children: [
              const SizedBox(height: 100),
              TextButton(
                  onPressed: () {
                    Get.toNamed('/address');
                  },
                  child: Text("跳转到地址页面")),
              TextButton(
                  onPressed: () {
                    Get.toNamed('/keyboard');
                  },
                  child: Text("keyboard")),
              Padding(
                padding: EdgeInsets.only(top: 150),
                child: FilledButton(
                  onPressed: () async {
                    ///打开游戏
                    final Uri url = Uri.parse(
                        "playhiveandroid://xoos.com/box?newGameAppPackageName=com.xx.xx");

                    /// 如果安装成功直接打开
                    if (await launchUrl(url,
                        mode: LaunchMode.externalApplication)) {}
                  },
                  child: Text("deeplink"),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }
}
